package com.jeasonzhao.commons.parser.lex;

import com.jeasonzhao.commons.basic.StringCollection;

public class CPPTokenizer extends BaseTokenizer
{
    public CPPTokenizer()
    {
        super(KnownConfiguration.CPPConfiguration.getInstance());
    }

    public CPPTokenizer(String str)
    {
        super(KnownConfiguration.CPPConfiguration.getInstance(),str);
    }

    public StringCollection getIncludeFiles()
        throws LexException
    {
        this.reload();
        StringCollection ret = new StringCollection();
        java.util.HashSet<String> set = new java.util.HashSet<String>();
        while(true)
        {
            LexToken k = this.nextToken();
            if(k == null)
            {
                break;
            }
            if(k.isName() && k.getToken().equals("#include"))
            {
                k = this.nextToken();
                if(null == k)
                {
                    break;
                }
                //System.out.println(k.getToken()+"*****"+k.getType());
                String strFileName = null;
                if(k.isSpecial())
                {
                    k = this.nextToken();
                }
                if(k.isName() || k.isString())
                {
                    strFileName = k.getToken();
                }
                if(null != strFileName && set.contains(strFileName) == false)
                {
                    set.add(strFileName);
                    ret.add(strFileName);
                }
            }
        }
        this.reload();
        return ret;
    }
}
